﻿Namespace Connection

    ''' <summary>
    ''' コネクションを管理するクラス
    ''' </summary>
    ''' <remarks></remarks>
    Public MustInherit Class Connector

        Public Shared Function Instance() As Connector
            Return KairyuSectionHandlerFactory.Create.GetCurrentDatabase.CreateConnector
        End Function

        'Public Shared Function Instance(name As String) As Connector
        '    Return KairyuSectionHandlerFactory.Create.GetCurrentDatabase.CreateConnector
        'End Function

        ''' <summary>
        ''' 接続文字列の復号コンバーター。指定されていない場合は無視されます。
        ''' </summary>
        Public Shared Decoder As Func(Of String, String)

        Private _connectionString As String
        ''' <summary>
        ''' 接続文字列を取得します。
        ''' </summary>
        Public Property ConnectionString As String
            Get
                Return _connectionString
            End Get
            Protected Friend Set(ByVal value As String)
                _connectionString = value
            End Set
        End Property

        Private _databaseName As String
        ''' <summary>
        ''' DB名を取得します。
        ''' </summary>
        Public Property DatabaseName As String
            Get
                Return _databaseName
            End Get
            Protected Friend Set(ByVal value As String)
                _databaseName = value
            End Set
        End Property

        Private _DBMS As DBMS
        ''' <summary>
        ''' DBMS名を取得します。
        ''' </summary>
        ''' <remarks>
        ''' #90　DBMS名を管理する
        ''' </remarks>
        Public Property DBMS As DBMS
            Get
                Return _DBMS
            End Get
            Protected Friend Set(value As DBMS)
                _DBMS = value
            End Set
        End Property

        Private _parameterSymbol As String
        ''' <summary>
        ''' パラメータ記号を取得します。
        ''' </summary>
        Public Property ParameterSymbol As String
            Get
                Return _parameterSymbol
            End Get
            Protected Friend Set(ByVal value As String)
                _parameterSymbol = value
            End Set
        End Property

        ''' <summary>
        ''' コネクションクラスを作成します。
        ''' </summary>
        Public MustOverride Function Connect() As System.Data.IDbConnection

        Public Overridable Function Transact() As DbTransactionWrapper
            Dim trn = Connect.BeginTransaction
            Return New DbTransactionWrapper(trn)
        End Function
    End Class

End Namespace